package 网络编程;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class fuwuqi {
    public static void main(String[] args) {
        //1.创建ServerSocket 服务器Socket
        try {
            //1.创建ServerSocket
            ServerSocket serverSocket=new ServerSocket(9879);
            //2.让服务器监听改端口
            Socket socket = serverSocket.accept();//监听端口
            //3，从Socket获取输入流
            InputStream is=socket.getInputStream();
            BufferedReader bis=new BufferedReader(new InputStreamReader(is));
            //4.调用输入流read读取信息
            String info=null;
            while ((info=bis.readLine())!=null){
                System.out.print(info);
            }
            String result="登陆成功";
            OutputStream os=socket.getOutputStream();
            BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os));
            bw.write(result);
            bw.flush();
            bis.close();
            is.close();
            bw.close();
            os.close();
            socket.close();
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
